class EventEmitter {
    constructor() {
        this.events = {}
    }
    on(type, callback) {
        if (!this.events[type]) {
            this.events[type] = [callback]
        } else {
            this.events[type].push(callback)
        }
    }
    off(type, callback) {
        if (this.events[type]) {
            this.events[type] = this.events[type].filter(item => item !== callback)
        } else {
            return
        }
    }
    once(type, callback) {
        function fn() {
            callback();
            this.off(type, fn)
        }
        this.on(type, fn)
    }
    emit(type, ...reset) {
        this.events[type].forEach(fn => {
            fn.apply(this, reset)
        });
    }
}
const event = new EventEmitter();
const handle = (...rest) => {
    console.log(rest);
};
// event.on("click", handle);
// event.emit("click", 1, 2, 3, 4);
// event.off("click", handle);
// event.emit("click", 1, 2);
event.once("dbClick", () => {
    console.log(123456);
});
event.emit("dbClick");
event.emit("dbClick");

